#ifndef __COMMON_H__
#define __COMMON_H__

#include "hlog.h"
#include <linux/videodev2.h>
#include <pthread.h>

#ifdef __cplusplus
extern "C" {
#endif

#define PROJECT_VERSION "1.0"
#define PROJECT_BUILD_TIME "2025.8.30"

#define LOG_INFO(format, ...) hlogi(format, ##__VA_ARGS__)
#define LOG_WARN(format, ...) hlogw(format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) hloge(format, ##__VA_ARGS__)
#define LOG_DEBUG(format, ...) hlogd(format, ##__VA_ARGS__)

#define CLEAR(x) memset(&(x), 0, sizeof(x))

/* ====================== RKNN start ====================== */
#define RKNN_WIDTH 640
#define RKNN_HEIGHT 640
#define RKNN_PIXELFORMAT IMAGE_FORMAT_RGB888
/* ======================= RKNN end ======================= */

/* ====================== V4L2 start ====================== */
// #define CAM_DEBUG
// 只能二选一
// DMA 暂未添加
#define MMAP_BUF
// #define DMA_BUF
#define BUF_COUNT 3

// 两个摄像头只支持其中1个，不要两个都打开
// mipi摄像头
#define MIPI_CAM    // 启用 MIPI 摄像头
#define MIPI_CAM_NAME "mipi_cam"
#define MIPI_CAM_DEV "/dev/video0"    // 修改成自己的摄像头设备路径（ov5695默认 /dev/video0）
#define MIPI_CAM_WIDTH 640
#define MIPI_CAM_HEIGHT 640
#define MIPI_CAM_PIXELFORMAT V4L2_PIX_FMT_NV12

// usb摄像头
// #define USB_CAM    // 启用 USB 摄像头
#define USB_CAM_NAME "usb_cam"
#define USB_CAM_DEV "/dev/video9"    // 修改成自己的摄像头设备路径
#define USB_CAM_WIDTH 240
#define USB_CAM_HEIGHT 320
#define USB_CAM_PIXELFORMAT V4L2_PIX_FMT_MJPEG

/* ====================== V4L2 end ====================== */

/* ====================== dem start ====================== */
#define DRM_DEV "rockchip"
#define DISP_WIDTH 720
#define DISP_HEIGHT 1280
#define DISP_PIXELFORMAT DRM_FORMAT_RGB8888
/* ====================== dem end ====================== */

/**
 * @brief Image pixel format
 *
 */
typedef enum {
    IMAGE_FORMAT_GRAY8,
    IMAGE_FORMAT_RGB888,
    IMAGE_FORMAT_RGBA8888,
    IMAGE_FORMAT_YUV420SP_NV21,
    IMAGE_FORMAT_YUV420SP_NV12,
    IMAGE_FORMAT_BGR888,
    IMAGE_FORMAT_XBGR8888,
    IMAGE_FORMAT_XRGB8888,
    IMAGE_FORMAT_ARGB8888,
    IMAGE_FORMAT_ABGR8888,
} image_format_t;

/**
 * @brief Image buffer
 *
 */
typedef struct {
    int width;
    int height;
    int width_stride;
    int height_stride;
    image_format_t format;
    unsigned char *virt_addr;
    int size;
    int fd;
    int bpp;
} image_buffer_t;

/**
 * @brief Image rectangle
 *
 */
typedef struct {
    int left;
    int top;
    int right;
    int bottom;
} image_rect_t;

/**
 * @brief Image obb rectangle
 *
 */
typedef struct {
    int x;
    int y;
    int w;
    int h;
    float angle;
} image_obb_box_t;

#ifdef __cplusplus
}    // extern "C"
#endif

#endif    //__COMMON_H__